<?php

namespace App\Http\Controllers\Api;

use App\apitransifer\ArticlerTransfer;
use Illuminate\Http\Request;
use Modules\Shop\Entities\Article;

class ArticleController extends Controller
{
    //获取所有文章接口
    public function articles(){
        $cid = \request()->query('cid',0);
        if ($cid){
            $article = Article::where('category_id',$cid)->paginate(3);
        }else{
            $article = Article::paginate(3);
        }
        return $this->response->paginator($article,new ArticlerTransfer());
    }

    public function hotArticle(){
        return $this->response->collection(Article::where('iscommend',1)->get(),new ArticlerTransfer());
    }

    //获取单个文章接口
    public function article($id){
        //找到对应文章id数据，然后返回
        $article = Article::find($id);

        return $this->response->item($article,new ArticlerTransfer());
    }
}
